package util;

public class IdUtil {
	public static IdUtil instance = null;

	private static final long ONE_STEP = 100;
	private static long lastTime = System.currentTimeMillis();
	private static short count = 0;

	public synchronized static IdUtil getInstanse() {
		if (instance == null) {
			instance = new IdUtil();
		}
		return instance;
	}

	private IdUtil() {
	}

	public synchronized String getUID() {
		try {
			if (count == ONE_STEP) {
				boolean done = false;
				while (!done) {
					long now = System.currentTimeMillis();
					if (now == lastTime) {
						try {
							Thread.sleep(1);
						} catch (java.lang.InterruptedException e) {
						}
						continue;
					} else {
						lastTime = now;
						count = 0;
						done = true;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		String result = lastTime + "" + (count++);
		return result;
	}
	
	public static void main(String[] args) {
		System.out.println(IdUtil.getInstanse().getUID());
	}
}
